package org.gruposp2p.dnie.client.ui.dialogs;

import com.allen_sauer.gwt.log.client.Log;

import org.gruposp2p.dnie.client.ui.panel.MainPanel;
import org.gruposp2p.dnie.client.ui.panel.TopPanel;
import org.gruposp2p.dnie.client.util.URLConstants;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;


public class AccesingPrivateZoneDialog {
	
    interface Style extends CssResource {
            String button();
    }

    @UiField Style style;
    @UiField VerticalPanel mainPanel;

    private static DialogoCrearParticipanteUiBinder uiBinder = GWT
                    .create(DialogoCrearParticipanteUiBinder.class);

    interface DialogoCrearParticipanteUiBinder extends
            UiBinder<Widget, AccesingPrivateZoneDialog> {
    }

    @UiField DialogBox dialogBox;
    private HorizontalPanel buttonPanel;

    public AccesingPrivateZoneDialog() {
        uiBinder.createAndBindUi(this);
        mainPanel.add(getButtonPanel());
    }

    public HorizontalPanel getButtonPanel () {
    	buttonPanel = new HorizontalPanel();
    	buttonPanel.setWidth("100%");
        Button botonAceptar = new Button("<img src=\"images/accept_16x16.png\">&nbsp;Aceptar</img>");
        botonAceptar.addStyleName(style.button());
        botonAceptar.addClickHandler(botonAceptarHandler);
        buttonPanel.add(botonAceptar);
        Button botonCancelar = new Button("<img src=\"images/cancel_16x16.png\">&nbsp;Cancelar</img>");;
        botonCancelar.addStyleName(style.button());
        botonCancelar.addClickHandler(botonCancelarHandler);
        buttonPanel.add(botonCancelar);
        return buttonPanel;
    }

    public void show() {
        dialogBox.center();
        dialogBox.show();
    }
    
	public native void goToPrivateZone() /*-{ 
		$wnd.location.href=@org.gruposp2p.dnie.client.util.URLConstants::getPrivateUrl()();
	}-*/; 

    ClickHandler botonAceptarHandler = new ClickHandler() {
        public void onClick(ClickEvent event) {
            buttonPanel.removeFromParent();
            if (History.getToken().equals(TopPanel.HISTORY_UPLOAD_DOCUMENT)) {
                URLConstants.SELECTED_SECTION = "#%23uploadDocumentAuthenticated";
            } else if (History.getToken().equals(TopPanel.HISTORY_LOGIN)) {
                URLConstants.SELECTED_SECTION = "#%23loginAuthenticated";
            }
            //MainPanel.INSTANCE.setSelectedPanel(MainPanel.INSTANCE.privateCentralPanel);
            goToPrivateZone();
        }
    };

    ClickHandler botonCancelarHandler = new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            History.back();
        }
    };
	
}